package com.jimikongjian.service.dao.impl;

import com.jimikongjian.dao.IFollowing;
import com.jimikongjian.models.Following;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by fuxiuyang on 17/3/4.
 */
@Service("iFollowingImpl")
public class IFollowingImpl implements IFollowing {

    @Autowired
//    @Qualifier("followingMapper")
    private IFollowing iFollowing;

    /**
     * 通过自身id号，获取某一确定的关注信息
     *
     * @param id
     * @return List<Following>
     */
    public List<Following> getFollowingListById(int id) {
        if (id > 0){
            return iFollowing.getFollowingListById(id);
        }
        return null;
    }

    /**
     * 通过自身的id号，获取某一确定的关注信息
     *
     * @param id
     * @return Following
     */
    public Following getFollowingById(int id) {
        if (id > 0){
            List<Following> followingList = getFollowingListById(id);
            if (followingList.size() > 0){
                return followingList.get(0);
            }

        }
        return null;
    }

    /**
     * 通过用户id，查找自己正在关注用户的信息
     *
     * @param userId
     * @return List<Following>
     */
    public List<Following> getFollowingListByUserId(int userId) {
        if (userId > 0){
            return iFollowing.getFollowingListByUserId(userId);
        }
        return null;
    }

    /**
     * 通过被关注者的id，查找正在关注自己的用户
     *
     * @param followingId
     * @return List<Following>
     */
    public List<Following> getFollowingListByFollowingId(int followingId) {
        if (followingId > 0){
            return iFollowing.getFollowingListByFollowingId(followingId);
        }
        return null;
    }

    /**
     * 创建一个新的关注
     *
     * @param following
     */
    public void insertFollowing(Following following) {
        if (following.getUserId() > 0
                && following.getUserNick() != ""
                && following.getFollowingId() > 0
                && following.getFollowingNick() != ""){
            iFollowing.insertFollowing(following);
        }
    }

    /**
     * 更新一个新的关注
     *
     * @param following
     */
    public void updateFollowing(Following following) {
//        关注没有更新，只有删除
    }

    /**
     * 删除一个关注
     * 通过用户的id号和关注者的id号删除
     *
     * @param following
     */
    public void deleteFollowing(Following following) {
        if (following.getUserId() > 0
                && following.getFollowingId() > 0){
            iFollowing.deleteFollowing(following);
        }

    }
}
